package beanstao.util.store.database.interfaces;

import java.sql.Connection;

import org.apache.commons.dbutils.ResultSetHandler;

import beanstao.util.store.database.DbSetting;

public interface IDbHelper
{
	public abstract Connection getConnection();

	/**
	 * 执行 Sql 语句,返回结果为整型主要用于执行非查询语句
	 * 
	 * @param cmdText
	 *            Sql 语句
	 * @return 非负数:正常执行; -1:执行错误;
	 */
	public abstract int update(String cmdText);

	/**
	 * 执行 Sql 语句,返回结果为整型 主要用于执行非查询语句
	 * 
	 * @param sql
	 * @param param
	 * @return
	 */
	public abstract int update(String sql, Object param);

	/**
	 * 执行 Sql 语句,返回结果为整型 主要用于执行非查询语句
	 * 
	 * @param cmdText
	 *            需要 ? 参数的 Sql 语句
	 * @param cmdParams
	 *            Sql 语句的参数表
	 * @return 非负数:正常执行; -1:执行错误;
	 */
	public abstract int update(String cmdText, Object... cmdParams);

	/**
	 * 批量执行 Sql 语句, 返回结果为整型. 主要用于执行无参数语句
	 * 
	 * @param cmdText
	 *            Sql 语句
	 * @return 非负数:正常执行; -1:执行错误;
	 */
	public abstract int[] batch(String... cmdTextList);

	/**
	 * Execute a batch of SQL INSERT, UPDATE, or DELETE queries. The <code>Connection</code> is retrieved from the
	 * <code>BoneCP</code> set in the constructor. This <code>Connection</code> must be in auto-commit mode or the update will
	 * not be saved.
	 * 
	 * @param sql
	 *            The SQL to execute.
	 * @param params
	 *            An array of query replacement parameters. Each row in this array is one set of batch replacement values.
	 * @return The number of rows updated per statement.
	 */
	public abstract int[] batch(String sql, Object[][] params);

	/**
	 * Executes the given SELECT SQL query and returns a result object. The <code>Connection</code> is retrieved from the
	 * <code>BoneCP</code> set in the constructor.
	 * 
	 * @param <T>
	 *            The type of object that the handler returns
	 * @param sql
	 *            The SQL statement to execute.
	 * @param rsh
	 *            The handler used to create the result object from the <code>ResultSet</code>.
	 * @param params
	 *            Initialize the PreparedStatement's IN parameters with this array.
	 * @return An object generated by the handler.
	 */
	public abstract <T> T query(String sql, ResultSetHandler<T> rsh, Object... params);

	/**
	 * Executes the given SELECT SQL without any replacement parameters. The <code>Connection</code> is retrieved from the
	 * <code>DataSource</code> set in the constructor.
	 * 
	 * @param <T>
	 *            The type of object that the handler returns
	 * @param sql
	 *            The SQL statement to execute.
	 * @param rsh
	 *            The handler used to create the result object from the <code>ResultSet</code>.
	 * 
	 * @return An object generated by the handler.
	 */
	public abstract <T> T query(String sql, ResultSetHandler<T> rsh);

	DbSetting getDbSetting();

	public abstract int update(String[] array);

}
